import moment from 'moment'
export const YearPanelMixin = {
  data(){
    return {
      yearShowOne: false,
      queryParamObj: {
        year: null
      }
    }
  },
  mounted(){
    //点击页面其他地方，关闭年选择器
    this.addEventListener()
  },
  beforeDestroy(){
    this.removeEventListener()
  },
  methods: {
    addEventListener(){
      let dom = document.querySelector(this.YearPanelDom)
      if(dom){
        dom.addEventListener('click', this.closepanel, true)
      }
    },
    removeEventListener(){
      let dom = document.querySelector(this.YearPanelDom)
      if(dom){
        dom.removeEventListener('click', this.closepanel, true)
      }
    },
    closepanel(){
      if(this.yearShowOne){
        this.yearShowOne = false
      }
    },
     // 弹出日历和关闭日历的回调
    openChangeOne(status) {
      if (status) {
        this.yearShowOne = true
      }
    },
    // 得到年份选择器的值
    panelChangeOne(value) {
      this.queryParamObj.year = value
      this.queryParam.year = moment(value).format('YYYY')
      this.yearShowOne = false
      this.clearMonth && this.clearMonth()
    },
    changeOne(value) {
      if (!value) {
        this.queryParamObj.year = null
        this.queryParam.year = ''
        this.yearShowOne = false
        this.clearMonth && this.clearMonth()
      }
    },
    searchResetClick(){
      this.queryParamObj = {}
      this.searchReset()
    },
  }
}